(function(){
	var AjaxCrud = QualityCheck.AjaxCRUD;
	var serverUrl = QualityCheck.GPUD.ServiceConfig;
	$(function(){
		initPages();
		window.onresize = function () {
			initPages();
		};
		initStudent();
		pageBtns();
	});
	function initStudent(){
		var userkey = $("#user-name",parent.document).attr("key");
		var usercode = $("#user-name",parent.document).attr("code");
		var data = {
				cmd:"getStudentByUserCode",
				model:"user",
				userKey:userkey,
				data:{
					usercode:usercode
				},
				remark:""					
		};
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			if(res.result == 1){
				var list = res.data;
				var imgContent = "";
				for(var i = 0; i < list.length; i++){
					if(i == 0){
						imgContent += "<div class='students-choice students-choice-select' classcode='" + list[i].classcode + "' studentcode='" + list[i].studentcode + "' name = '"+list[i].name+"' title = '"+list[i].name+"'><div class='students-choice-img'><img src=\"../../../../../"+ServiceName+list[i].headimg+"\" width='100%' height='100%'/></div><div class='students-choice-name'>"+substr(list[i].name,4)+"</div></div>";
					}else{
						imgContent += "<div class='students-choice' classcode='" + list[i].classcode + "' studentcode='" + list[i].studentcode + "' name = '"+list[i].name+"' title = '"+list[i].name+"'><div class='students-choice-img'><img src=\"../../../../../"+ServiceName+list[i].headimg+"\" width='100%' height='100%'/></div><div  class='students-choice-name'>"+substr(list[i].name,4)+"</div></div>";
					}
				}					
				$(".dialog-students-contents").empty();
				$(".dialog-students-contents").append(imgContent);
				changePage(PageUrl.ppositionUrl);
			}else{
				$(".dialog-students-contents").empty();
				$(".dialog-students-contents").append("<div class='students-choice students-choice-select'>没有相关信息</div>");
				changePage(PageUrl.ppositionUrl);
			}
		},null,null);
	}	
	function pageBtns(){
		$(".left-menu-ul li").click(function(){
			var title = $(this).attr("title");
			$(".left-menu-ul li").removeClass("left-menu-liselect");
			$(this).addClass("left-menu-liselect");
			if(title == "定位"){
				changePage(PageUrl.ppositionUrl);
			}else if(title == "历史足迹"){
				changePage(PageUrl.phistoryUrl);
			}else if(title == "报警信息"){
				changePage(PageUrl.psosUrl);
			}else if(title == "电子围栏"){
				changePage(PageUrl.fenceUrl);
			}
		});
		$(".dialog-display-btnshow").click(function(){
			$(".dialog-display-btnshow").hide();
			$(".dialog-display-btnhide").show();
			$(".student-choice-classdia").animate({right:"0px"});
		});
		$(".dialog-display-btnhide").click(function(){
			$(".dialog-display-btnshow").show();
			$(".dialog-display-btnhide").hide();
			$(".student-choice-classdia").animate({right:"-120px"});
		});
	}
	function substr(str,len){
		if(str != undefined){
			if(str.length > len){
				str = str.substring(0,len-2)+"...";
				return str;
			}else{
				return str;
			}
		}else{
			return "";
		}
	}
	function changePage(pageUrl){
		$("#aposition-body").attr("src",pageUrl);
	}
	function initPages(){
		var bodyRW = $(".index-body",parent.document).width() - $(".quality-left-page-menu").width()-2;
		$("#aposition-body").width(bodyRW);
	}
	
})();